package com.play.ballen.network;

import com.franmontiel.persistentcookiejar.ClearableCookieJar;
import com.franmontiel.persistentcookiejar.PersistentCookieJar;
import com.franmontiel.persistentcookiejar.cache.SetCookieCache;
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor;
import com.play.ballen.BuildConfig;
import com.yuven.appframework.network.CommonRetrofitManager;
import com.yuven.baselib.utils.ToolsKit;

import okhttp3.OkHttpClient;

public class RetrofitManager extends CommonRetrofitManager {

    private ApiService apiService;

    private RetrofitManager() {
    }
    @Override
    protected String getBaseUrl() {
        return BuildConfig.BASE_URL;
    }

    @Override
    protected void addInterceptor(OkHttpClient.Builder builder) {
        super.addInterceptor(builder);
        builder.addInterceptor(new BallenHeaderInterceptor());

        ClearableCookieJar cookieJar =
                new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(ToolsKit.getClient()));
        builder.cookieJar(cookieJar);
    }

    private static class InstanceHolder {
        private static RetrofitManager sMainRetrofitManager = new RetrofitManager();
    }

    public static RetrofitManager getInstance() {
        return InstanceHolder.sMainRetrofitManager;
    }

    @Override
    protected void initService() {
        apiService = createService(ApiService.class);
    }

    public ApiService getApiService() {
        return apiService;
    }

}
